﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace CoffeeBar_WebService
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService : System.Web.Services.WebService
    {
        CoffeeBarDataContext context = new CoffeeBarDataContext();

#region kiemtratontai
        [WebMethod]
        public bool kiemtratontai_BAN(Int32 MaBan)//kiểm tra tồn tại bàn có mã số MaBan hay chưa.
        {
            return (context.kiemtra_tontai_BAN(MaBan) == 1) ? true : false;
        }
        [WebMethod]
        public bool kiemtratontai_CA(Int32 MaCa)//kiểm tra tồn tại Ca co ma so hay chưa.
        {
            return (context.kiemtratontai_CA(MaCa) == 1) ? true : false;
        }
        [WebMethod]
        public bool kiemtratontai_CHUYENMUC(Int32 MaChuyenMuc)//kiểm tra tồn tại chuyen muc
        {
            return (context.kiemtratontai_CHUYENMUC(MaChuyenMuc) == 1) ? true : false;
        }
        [WebMethod]
        public bool kiemtratontai_DATBAN(Int32 MaDatBan)//kiểm tra tồn tại dat ban
        {
            return (context.kiemtratontai_DATBAN(MaDatBan) == 1) ? true : false;
        }
        [WebMethod]
        public bool kiemtratontai_DATHANG(Int32 MaDatHang)//kiểm tra tồn tại dat hang
        {
            return (context.kiemtratontai_DATHANG(MaDatHang) == 1) ? true : false;
        }
#endregion
#region them
        [WebMethod]
        public bool them_BAN(Int32 MaKhuVuc,Int32 SoGhe)//them ban
        {
            try
            {
                context.them_BAN(MaKhuVuc, SoGhe);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool them_CA(TimeSpan BatDau,TimeSpan KetThuc,float HeSoLuong)//them ca
        {
            try
            {
                context.them_CA(BatDau,KetThuc,HeSoLuong);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool them_CHUYENMUC(string TenChuyenMuc)//them chuyen muc
        {
            try
            {
                context.them_CHUYENMUC(TenChuyenMuc);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool them_DATBAN(DateTime NgayDat,TimeSpan ThoiGianBatDau,TimeSpan ThoiGianKetThuc)//them dat ban
        {
            try
            {
                context.them_DATBAN(NgayDat,ThoiGianBatDau,ThoiGianKetThuc);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool them_DATHANG(Int32 MaKH,Int32 MaNhanVien,string DiaChiGiao,DateTime ThoiGianDat,DateTime ThoiGianYeuCau,short TinhTrangGiao,short TinhTrangThanhToan)//them dat hang
        {
            try
            {
                context.them_DATHANG(MaKH,MaNhanVien,DiaChiGiao,ThoiGianDat,ThoiGianYeuCau,TinhTrangGiao,TinhTrangThanhToan);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }
        [WebMethod]
        public bool them_LOAIMATHANG(string TenLoaiMatHang)
        {
            try
            {
                return true;
            }
            catch(System.Exception e)
            {
                return false;
            }
        }
        [WebMethod]
        public bool them_LOAIHANG(string TenLoaiHang)
        {
            try
            {
                context.them_LOAIHANG(TenLoaiHang);                
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
        [WebMethod]
        public bool them_HANGBAN(Int32 maloaihang, string tenhang,long dongia,string gioithieu, Int32 sanco, short diemdanhgia)
        {
            try
            {
                int temp=context.them_HANGBAN(maloaihang, tenhang, dongia, gioithieu, sanco, diemdanhgia);
                if (temp == 1) return true;
                else return false;
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
#endregion
#region xoa
        [WebMethod]
        public bool xoa_BAN(Int32 MaBan)//huy ban
        {
            try
            {
                context.xoa_BAN(MaBan);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool xoa_CA(Int32 MaCa)//huy ca
        {
            try
            {
                context.xoa_CA(MaCa);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool xoa_CHUYENMUC(Int32 MaChuyenMuc)//huy chuyen muc
        {
            try
            {
                context.xoa_CHUYENMUC(MaChuyenMuc);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
        [WebMethod]
        public bool xoa_DATBAN(Int32 MaDatBan)//huy dat ban
        {
            try
            {
                context.xoa_DATBAN(MaDatBan);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
        [WebMethod]
        public bool xoa_DATHANG(Int32 MaDatHang,DateTime TuNgay,DateTime DenNgay)//huy dat hang...theo ma dat hang....theo khoang thoi gian dat hang
        {
            try
            {
                context.xoa_DATHANG(MaDatHang,TuNgay,DenNgay);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
        [WebMethod]
        public bool xoa_LOAIHANG(int maloaihang)
        {
            try
            {
                context.xoa_LOAIHANG(maloaihang);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
        [WebMethod]
        public bool xoa_HANGBAN(Int32 id)
        {
            try
            {
                context.xoa_HANGBAN(id);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
#endregion
#region sua
        [WebMethod]
        public bool sua_BAN(Int32 MaBan,Int32 MaKhuVuc, Int32 SoGhe)//sua ban
        {
            try
            {
                context.sua_BAN(MaBan,MaKhuVuc, SoGhe);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool sua_CA(Int32 MaCa,TimeSpan BatDau, TimeSpan KetThuc, float HeSoLuong)//sua ca
        {
            try
            {
                context.sua_CA(MaCa,BatDau, KetThuc, HeSoLuong);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool sua_CHUYENMUC(Int32 MaChuyenMuc,string TenChuyenMuc)//sua chuyen muc
        {
            try
            {
                context.sua_CHUYENMUC(MaChuyenMuc,TenChuyenMuc);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool sua_DATBAN(Int32 MaDatBan,DateTime NgayDat, TimeSpan ThoiGianBatDau, TimeSpan ThoiGianKetThuc)//sua dat ban
        {
            try
            {
                context.sua_DATBAN(MaDatBan,NgayDat, ThoiGianBatDau, ThoiGianKetThuc);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool sua_DATHANG(Int32 MaDatHang,Int32 MaKH, Int32 MaNhanVien, string DiaChiGiao, DateTime ThoiGianDat, DateTime ThoiGianYeuCau, short TinhTrangGiao, short TinhTrangThanhToan)//sua dat hang
        {
            try
            {
                context.sua_DATHANG(MaDatHang,MaKH, MaNhanVien, DiaChiGiao, ThoiGianDat, ThoiGianYeuCau, TinhTrangGiao, TinhTrangThanhToan);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }
        [WebMethod]
        public bool sua_LOAIHANG(string id, string item_name)
        {
            try
            {
                context.sua_LOAIHANG(Convert.ToInt32(id), item_name);
            }
            catch (System.Exception e)
            {
                return false;
            }
            return true;
        }
        [WebMethod]
        public bool sua_HANGBAN(long mahang,Int32 maloaihang, string tenhang, long dongia, string gioithieu, int cosan, short diemdanhgia)
        {
            try
            {
                context.sua_HANGBAN(mahang, maloaihang, tenhang,dongia, gioithieu, cosan, diemdanhgia);
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
#endregion
#region laydanhsach
        [WebMethod]
        public List<BAN> laydanhsach_BAN(Int32 MaBan)//lay danh sach ban:neu ton tai MaBan se return Ban do.Neu ko ton tai se tra ve tat ca cac ban
        {
            var result = context.laydanhsach_BAN(MaBan);
            return result.ToList();
        }
        [WebMethod]
        public List<CA> laydanhsach_CA(Int32 MaCa)//lay danh sach ca:neu ton tai MaCa se return Ca  do.Neu ko ton tai se tra ve tat ca cac CA
        {
            return context.laydanhsach_CA(MaCa).ToList();
        }
        [WebMethod]
        public List<CHUYENMUC> laydanhsach_CHUYENMUC(Int32 MaChuyenMuc)//lay danh sach chuyen muc:neu ton tai MaChuyenMuc se return chuyen muc do.
            //Neu ko ton tai se tra ve tat ca cac chuyen muc
        {
            return context.laydanhsach_CHUYENMUC(MaChuyenMuc).ToList();
        }
        [WebMethod]
        public List<DATBAN> laydanhsach_DATBAN(Int32 MaDatBan,DateTime TuNgay,DateTime DenNgay)//lay danh sach dat ban:
            //neu ton tai MaBan se return Ban do.Neu ko ton tai se tra ve tat ca cac ban ->theo khoang thoi gian
        {
            return context.laydanhsach_DATBAN(MaDatBan, TuNgay, DenNgay).ToList();
        }
        [WebMethod]
        public List<LOAIHANG> laydanhsach_LOAIHANG()//lay tu linq
        {
            return context.LOAIHANGs.ToList();
        }
        [WebMethod]
        public List<laydanhsach_LOAIHANGResult> laydanhsach_LOAIHANG2(Int32 id) //lay tu store linq
        {
            return context.laydanhsach_LOAIHANG(id).ToList();
        }
        [WebMethod]
        public List<laydanhsach_HANGBANResult> laydanhsach_HANGBAN(Int32 id)
        {
            return context.laydanhsach_HANGBAN(id).ToList();
        }
#endregion
       
    }
}
